package com.dc.designPattern._8_composite.impl;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * Description: 组合模式_组件,学院
 *
 *  Composite :非叶子节点，用于存储子部件，在 Component 接口中实现 子部件的相关操作，比如增加(add), 删除。
 *
 * @author: gdc
 * @date: 2021/3/14
 * @version 1.0
 */
public class College extends OrganizationComponent {

    private List<OrganizationComponent> organizationComponents = Lists.newArrayList();

    public College(String name, String desc) {
        super(name, desc);
    }

    @Override
    protected void add(OrganizationComponent organizationComponent) {
        //  将来实际业务中，Colleage 的 add 和  University add 不一定完全一样
        organizationComponents.add(organizationComponent);
    }

    @Override
    protected void remove(OrganizationComponent origanizationComponent) {
        organizationComponents.remove(origanizationComponent);
    }

    @Override
    protected void print() {
        System.out.println("** " + getName());
        organizationComponents.forEach(OrganizationComponent::print);
    }
}
